package com.excesys.exsecs.admin.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.admin.api.entity.SysPageDesign;
import com.excesys.exsecs.admin.service.SysPageDesignService;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import org.springframework.security.access.prepost.PreAuthorize;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 系统页面设计
 *
 * @author lxc
 * @date 2024-11-18 14:06:29
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysPageDesign" )
@Tag(description = "sysPageDesign" , name = "系统页面设计管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysPageDesignController {

    private final SysPageDesignService sysPageDesignService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param sysPageDesign 系统页面设计
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_view')" )
    public R getSysPageDesignPage(@ParameterObject Page page, @ParameterObject SysPageDesign sysPageDesign) {
        return R.ok(sysPageDesignService.queryPage(page, sysPageDesign));
    }


    /**
     * 通过id查询系统页面设计
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_view')" )
    public R getById(@PathVariable("id" ) Integer id) {
        return R.ok(sysPageDesignService.getDesign(id));
    }

    /**
     * 新增系统页面设计
     * @param sysPageDesign 系统页面设计
     * @return R
     */
    @Operation(summary = "新增系统页面设计" , description = "新增系统页面设计" )
    @SysLog("新增系统页面设计" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_add')" )
    public R save(@RequestBody SysPageDesign sysPageDesign) {
        return R.ok(sysPageDesignService.saveDesign(sysPageDesign));
    }

    /**
     * 修改系统页面设计
     * @param sysPageDesign 系统页面设计
     * @return R
     */
    @Operation(summary = "修改系统页面设计" , description = "修改系统页面设计" )
    @SysLog("修改系统页面设计" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_edit')" )
    public R updateById(@RequestBody SysPageDesign sysPageDesign) {
        return R.ok(sysPageDesignService.updateDesign(sysPageDesign));
    }

    /**
     * 通过id删除系统页面设计
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除系统页面设计" , description = "通过id删除系统页面设计" )
    @SysLog("通过id删除系统页面设计" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_del')" )
    public R removeById(@RequestBody Integer[] ids) {
        return R.ok(sysPageDesignService.removeBatchDesign(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param sysPageDesign 查询条件
   	 * @param ids 导出指定ID
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('sys_sysPageDesign_export')" )
    public List<SysPageDesign> export(SysPageDesign sysPageDesign,Integer[] ids) {
        return sysPageDesignService.list(Wrappers.lambdaQuery(sysPageDesign).in(ArrayUtil.isNotEmpty(ids), SysPageDesign::getId, ids));
    }
}